home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 1.iso
/
DEMON
/
DEVELOPER
/
FREENET
/
WORKBONE.ARC
/
Linux
/
WBone2
/
workbone2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-29
|
7KB
|
313 lines
/* WorkBone CD Rom Player Software
Copyright (C) 1993 Thomas McWilliams
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Modified for use with the Acorn RISC-OS WorkBone client software.
* An original version of WorkBone is supplied with the distribution
* of this software.
*
* No warranties etc. Tony Howat (thowat@xargle.demon.co.uk) 28/05/95
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
#include <signal.h>
#include <unistd.h>
#include <termios.h>
#include <mntent.h>
#include <getopt.h>
#include "struct.h"
#include "workbone2.h"
void control_panel (void);
void rl_ttyset (int Reset);
void strmcpy (char **t, char *s);
void help (void);
inline void playtime (void);
char *cur_trackname; /* Take a guess */
int cur_index = 0; /* Current index mark */
int cur_frame; /* Current frame number */
struct play *playlist = NULL;
struct cdinfo thiscd, *cd = &thiscd;
int cur_track = -1; /* Current track number, starting at 1 */
char *cur_artist; /* Name of current CD's artist */
char cur_avoid; /* Avoid flag */
char cur_contd; /* Continued flag */
char *cur_cdname; /* Album name */
int cur_nsections; /* Number of sections currently defined */
int exit_on_eject = 0;
int cur_balance = 10, info_modified;
int cur_track, cur_pos_abs, cur_pos_rel, cur_tracklen, cur_cdlen, cur_cdmode,
cur_ntracks, cur_lasttrack, cur_firsttrack, cur_listno;
char tmptime[100];
char *tottime;
int
main (int argc, char *argv[])
{
int sss, sel_stat, dly;
int fastin = FALSE;
int scmd = 0, tmppos = 0;
int save_track = 1;
fd_set rset;
struct timeval mydelay;
struct mntent *mnt ;
char copt;
FILE *fp ;
thiscd.trk = NULL;
thiscd.lists = NULL;
mydelay.tv_sec = 0;
mydelay.tv_usec = 200000;
tottime = tmptime;
/* get options */
for (;;)
{
if ((copt = getopt (argc, argv, "hqvV")) == EOF)
break;
switch (copt)
{
case 'q':
fastin = TRUE;
break;
default:
printf ("\nWorkBone version 0.1 Copyright 1993 (c) Thomas McWilliams\n");
printf ("This version modified by Tony Howat for use with the\n");
printf ("RISC-OS workbone client.\n");
printf ("Free Software under GNU General Public License.\n\n");
printf ("Useage: workbone [ -v | -h | -q ]\n");
printf (" -v : version\n");
printf (" -h : help\n");
printf (" -q : fast start (no wait for init)\n\n");
printf ("Type 'workbone' to start program.\n\n");
printf ("Engage the NUM LOCK on your keypad. From inside WorkBone\n");
printf ("pressing DEL on numeric keypad will display a help menu.\n\n");
exit (0);
}
}
/* check if drive is mounted (from Mark Buckaway's cdplayer code) */
if ((fp = setmntent (MOUNTED, "r")) == NULL)
{
fprintf (stderr, "Couldn't open %s: %s\n", MOUNTED, strerror (errno));
exit (1);
}
while ((mnt = getmntent (fp)) != NULL)
{
if (strcmp (mnt->mnt_type, "iso9660") == 0)
{
fputs ("CDROM already mounted. Operation aborted.\n", stderr);
endmntent (fp);
exit (1);
}
}
endmntent (fp);
/* delay while CD drive initializes itself */
if (!fastin)
for (dly = 6; dly > -1; dly--)
{
printf ("wait ... initializing %d\r", dly);
fflush (stdout);
sleep (1);
}
printf (" \r");
fflush (stdout);
sss = cd_status ();
rl_ttyset (0);
if (sss == 0 || sss == 4)
goto done;
cur_track = 1;
printf ("ready\r");
fflush(stdout);
do
{
/*
use select() to update status every 200 millisecs or
sooner if keypad has data
*/
FD_ZERO (&rset);
FD_SET (STDIN_FILENO, &rset);
sel_stat = select (4, &rset, NULL, NULL, &mydelay);
sss = cd_status ();
if (sss == 0 || sss == 4 || cur_cdmode == CDEJECT)
{
scmd = '0';
goto done;
}
if (cur_cdmode < 1)
save_track = 1;
/* if key was pressed, parse it and do function */
if (FD_ISSET (STDIN_FILENO, &rset))
{
read (0, &scmd, 1);
switch (scmd & 255)
{
case '.':
case '?':
help ();
break;
case '1':
if (cur_cdmode == CDPLAY)
{
tmppos = cur_pos_rel - 15;
play_cd (cur_track, tmppos > 0 ? tmppos : 0, cur_ntracks + 1);
}
break;
case '3':
if (cur_cdmode == CDPLAY)
{
tmppos = cur_pos_rel + 15;
if (tmppos < thiscd.trk[cur_track - 1].length)
play_cd (cur_track, tmppos, cur_ntracks + 1);
}
break;
case '2':
stop_cd ();
eject_cd ();
break;
case '4':
cur_track--;
if (cur_track < 1)
cur_track = cur_ntracks;
play_cd (cur_track, 0, cur_ntracks + 1);
break;
case '5':
if (cur_cdmode == CDPLAY)
play_cd (cur_track, 0, cur_ntracks + 1);
break;
case '6':
if (cur_track == cur_ntracks)
cur_track = 0;
play_cd (cur_track + 1, 0, cur_ntracks + 1);
break;
case '7':
save_track = cur_track;
stop_cd ();
break;
case '8':
if (cur_cdmode == CDPLAY || cur_cdmode == CDPAUZ)
{
pause_cd ();
}
break;
case '9':
if (cur_cdmode == CDSTOP || cur_cdmode == CDNULL)
{
play_cd (save_track, 0, cur_ntracks + 1);
}
break;
default:
break;
}
}
/* update display of which track is playing */
switch (cur_cdmode)
{
case 0: /* CDNULL */
cur_track = save_track = 1;
printf ("stp\r");
break;
case 1: /* CDPLAY */
playtime ();
printf ("ply,%d,%s\r", cur_track, tottime);
break;
case 3: /* CDPAUZ */
printf ("pse,%d \r", cur_track);
break;
case 4: /* CDSTOP */
printf ("stp,%d \r", save_track);
break;
case 5: /* CDEJECT */
goto done;
default:
printf ("cur_cdmode %d \r", cur_cdmode);
}
fflush (stdout);
}
while (scmd != '0');
done:
if (thiscd.trk != NULL)
free (thiscd.trk);
printf ("close\r");
printf ("\n");
rl_ttyset (1);
return(0);
}
/* takes terminal in and out of raw mode */
void
rl_ttyset (int Reset)
{
}
/* Copy into a malloced string. */
void
strmcpy (char **t, char *s)
{
if (*t != NULL)
free (*t);
*t = malloc (strlen (s) + 1);
if (*t == NULL)
{
perror ("strmcpy");
exit (1);
}
(void) strcpy (*t, s);
}
/* ansi codes to clear screen */
void
cls ()
{
}
/* print help screen */
void
help ()
{
}
inline void
playtime (void)
{
static int mymin, emin;
static int mysec, esec;
int tmp = 0;
if (cur_pos_rel > 0 && (tmp = cur_pos_rel % 60) == mysec)
return;
mysec = tmp;
mymin = cur_pos_rel / 60;
esec = cur_pos_abs % 60;
emin = cur_pos_abs / 60;
sprintf (tmptime, "%02d,%02d",mymin, mysec);
return;
}